#-*- coding:UTF-8 -*-

import os.path

PLATMGT_HOME = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]

def _get_sys_properties():
    properties = {}
    with open(os.path.join(PLATMGT_HOME, 'CONF', 'sys.conf')) as f:
        for line in f.readlines():
            line = line.strip()
            if line and line[0] != '#':
                kv = line.split('=', 1)
                if len(kv) == 2:
                    properties[kv[0]] = kv[1]
                else:
                    print('incorrect config setting: %s'%line)
    return properties


SYS_PROPERTIES = _get_sys_properties()

def refresh_properties():
    SYS_PROPERTIES = _get_sys_properties()


def get_property(property_name, default_value=''):
    if SYS_PROPERTIES.has_key(property_name):
        return SYS_PROPERTIES[property_name]
    else:
        return default_value
